package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysFmSort;
import com.hl.sfzy.service.SysFmSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: sfzy
 * @ClassName sysFmSortControlle
 * @description:
 * @author: lyp
 * @create: 2024-07-12 22:00
 * @Version 1.0
 **/
@RestController
public class sysFmSortController {
    @Autowired
    private SysFmSortService sysFmSortService;

    //新增
    @PostMapping("/sysFmSort")
    public Result add(@RequestBody SysFmSort sysFmSort){
        int num = sysFmSortService.add(sysFmSort);
        return num > 0 ? Result.success() : Result.error();
    }

    //删除
    @DeleteMapping("/sysFmSort/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysFmSortService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/sysFmSort")
    public Result removeBatch(Integer[] ids){
        int num = sysFmSortService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    //修改
    @PutMapping("/sysFmSort")
    public Result edit(@RequestBody SysFmSort sysFmSort){
        int num = sysFmSortService.edit(sysFmSort);
        return num > 0 ? Result.success() : Result.error();
    }

    //根据id查询
    @GetMapping("/sysFmSort/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysFmSort sysFmSort = sysFmSortService.findById(id);
        return Result.success(sysFmSort);
    }

    //查询所有
    @GetMapping("/sysFmSort")
    public Result findAll(SysFmSort sysFmSort){
        List<SysFmSort> list = sysFmSortService.find(sysFmSort);
        return Result.success(list);
    }

    //分页查询
    @GetMapping("/sysFmSort/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysFmSort sysFmSort){
        Map<String,Object> map = sysFmSortService.findPage(pageNum, pageSize, sysFmSort);

        return Result.success(map);
    }

}

